package org.demo.test.springbatch;

import com.hundsun.jrescloud.db.core.dynamic.DynamicDataSource;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.jdbc.datasource.DataSourceTransactionManager;

import javax.annotation.Resource;
import javax.sql.DataSource;

@Configuration
public class DataSourceAutoConfig {

    @Resource
    DynamicDataSource dynamicDataSource;

    @Bean("batchDataSource")
    public DataSource batchDataSource() {
        return dynamicDataSource.getDataSource("batch");
    }

    @Bean("batchTransactionManager")
    public DataSourceTransactionManager batchTransactionManager(@Qualifier("batchDataSource") DataSource dataSource) {
        return new DataSourceTransactionManager(dataSource);
    }
}
